// 处理路由
function filterRouter(array) {
  const list = Array.from(new Set(array))
  list.map(item => {
    if (item.component) item.component = loadView(item.component)
  })
  return list
}
// function loadViewDev(file) {
//   return require('@/pages' + file).default
// }
// function loadViewProd(file) {
//   return () => import('@/pages' + file)
// }
// const loadView = process.env.NODE_ENV === 'development' ? loadViewDev : loadViewProd
function loadView(file) {
  return process.env.NODE_ENV === 'development'
    ? require('@/pages/module' + file).default
    : () => import('@/pages/module' + file)
}
// 处理菜单
let index = 0
function filterMenu(array) {
  array.map(item => {
    if (!item.path) {
      item.path = 'd2-menu-empty-' + JSON.stringify(JSON.parse(index))
      index++
    }
    item.children && filterMenu(item.children)
  })
  return array
}

export default filterRouter
export {
  filterRouter,
  filterMenu
}
